package com.hex.ds.hdrs.period.job.vo.query;

import cn.hutool.core.util.StrUtil;
import lombok.Data;
import org.apache.commons.collections.CollectionUtils;

import java.io.Serializable;
import java.util.Arrays;
import java.util.List;

@Data
public class PeriodJobDefQueryVo implements Serializable {

    private String appCode;

    private String appName;

    private String jobCodeFuzzy;

    private List<String> jobCodeList;

    private String jobNameFuzzy;

    private List<String> jobNameList;

    private String labelName;

    private String batchTag;

    private String jobPeriod;

    private String jobStatus;

    private String jobNameAndJobCode;

    private String startTimeStart;

    private String startTimeEnd;

    private String endTimeStart;

    private String endTimeEnd;

    private List<String> startTime;

    private List<String> endTime;

    public String getJobCodeFuzzy() {
        if (StrUtil.isNotBlank(jobCodeFuzzy) && (jobCodeFuzzy.contains(",") || jobCodeFuzzy.contains("，"))) {
            return null;
        }
        return (StrUtil.isNotBlank(jobCodeFuzzy)) ? jobCodeFuzzy.toUpperCase() : null;
    }

    public String getJobNameFuzzy() {
        if (StrUtil.isNotBlank(jobNameFuzzy) && (jobNameFuzzy.contains(",") || jobNameFuzzy.contains("，"))) {
            return null;
        }
        return jobNameFuzzy;
    }

    public String getLabelName() {
        if (StrUtil.isNotBlank(labelName) && (labelName.contains(",") || labelName.contains("，"))) {
            return null;
        }
        return labelName;
    }

    public List<String> getJobCodeList() {
        if (StrUtil.isNotBlank(jobCodeFuzzy) && (jobCodeFuzzy.contains(",") || jobCodeFuzzy.contains("，"))) {
            return Arrays.asList(jobCodeFuzzy.toUpperCase().replace("，", ",").split(","));
        }
        return jobCodeList;
    }

    public List<String> getJobNameList() {
        if (StrUtil.isNotBlank(jobNameFuzzy) && (jobNameFuzzy.contains(",") || jobNameFuzzy.contains("，"))) {
            return Arrays.asList(jobNameFuzzy.replace("，", ",").split(","));
        }
        return jobNameList;
    }

    public String getStartTimeStart() {
        if (CollectionUtils.isNotEmpty(startTime) && startTime.size() == 2) {
            return startTime.get(0);
        }
        return startTimeStart;
    }

    public String getStartTimeEnd() {
        if (CollectionUtils.isNotEmpty(startTime) && startTime.size() == 2) {
            return startTime.get(1);
        }
        return startTimeEnd;
    }

    public String getEndTimeStart() {
        if (CollectionUtils.isNotEmpty(endTime) && endTime.size() == 2) {
            return endTime.get(0);
        }
        return endTimeStart;
    }

    public String getEndTimeEnd() {
        if (CollectionUtils.isNotEmpty(endTime) && endTime.size() == 2) {
            return endTime.get(1);
        }
        return endTimeEnd;
    }
}
